package com.zygh.policeasset.controller;

import cn.hutool.core.util.StrUtil;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.Contract;
import com.zygh.policeasset.pojo.Section;
import com.zygh.policeasset.pojo.Tender;
import com.zygh.policeasset.service.CompletedSerivce;
import com.zygh.policeasset.service.ContractPayService;
import com.zygh.policeasset.service.ContractService;
import com.zygh.policeasset.service.FinalStatementService;
import com.zygh.policeasset.service.SectionService;
import com.zygh.policeasset.service.SettlementService;
import com.zygh.policeasset.service.TenderService;
import com.zygh.policeasset.service.UnitInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/archive"})
@Api(tags = {"归档管理模块"})
@RestController
public class ArchiveController {
    @Autowired
    TenderService tenderService;
    @Autowired
    SectionService sectionService;
    @Autowired
    ContractService contractService;
    @Autowired
    ContractPayService contractPayService;
    @Autowired
    CompletedSerivce completedSerivce;
    @Autowired
    SettlementService settlementService;
    @Autowired
    FinalStatementService finalStatementService;
    @Autowired
    UnitInformationService unitInformationService;

    @RequestMapping(value = {"/"}, method = {RequestMethod.GET})
    @ApiOperation("根据项目编号查询所有")
    public Object findAll(@RequestParam String project_no) {
        if (StrUtil.isEmpty(project_no)) {
            return new CommonResult().validateFailed("项目编号不能为空");
        }
        List<Tender> tenderList = this.tenderService.findByProjectNoPage(project_no);
        Section section = new Section();
        for (int i = 0; i < tenderList.size(); i++) {
            section.setTenderId(tenderList.get(i).getId());
            tenderList.get(i).setSectionList(this.sectionService.findAll(section));
        }
        List<Contract> contractList = this.contractService.findByProjectNoPage(project_no);
        for (int i2 = 0; i2 < contractList.size(); i2++) {
            contractList.get(i2).setContractPayList(this.contractPayService.findByProjectAndSection(contractList.get(i2).getProjectNo(), Integer.valueOf(contractList.get(i2).getId())));
        }
        Object completedList = this.completedSerivce.findByProjectNoPage(project_no);
        Object settlementList = this.settlementService.findByProjectNoPage(project_no);
        Object finalStatementList = this.finalStatementService.findByProjectNoPage(project_no);
        Object unitInformationList = this.unitInformationService.findByProjectNoPage(project_no);
        Map<String, Object> data = new HashMap<>(16);
        data.put("tender", tenderList);
        data.put("contract", contractList);
        data.put("completed", completedList);
        data.put("settlement", settlementList);
        data.put("finalstatement", finalStatementList);
        data.put("unitInformation", unitInformationList);
        return new CommonResult().success(data);
    }
}